<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>websocket测试</title>
  </head>
  <body style="margin: 0">
    <script>
      var websocket = null;
      if ("WebSocket" in window) {
        websocket = new WebSocket(
          "ws://192.168.1.23:8080/jschrjWebSocket/hard/jybl/110"
        );
      }

      websocket.onopen = function () {
        console.log("连接成功");
      };

      websocket.onclose = function () {
        console.log("退出连接");
      };

      websocket.onmessage = function (event) {
        console.log("收到消息" + event.data);
        var qdid = event.data;
      };

      websocket.onerror = function () {
        console.log("连接出错");
      };

      window.onbeforeunload = function () {
        websocket.close();
      };
    </script>
  </body>
</html>
